//
//  THTreeHoleDataController.m
//  TreeHole
//
//  Created by apple on 2020/9/18.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THTreeHoleDataController.h"

@implementation THTreeHoleDataController
//首页分类
+ (void)stoneobs_fun_get_home_cates_type:(NSString*)type handle:(void(^)(NSArray * cates))handle{

    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
if (type.length) {
    [stoneobs_net_param_dic setObject:type forKey:@"type"];
}
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/cate"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumGet
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSArray * stoneobs_net_array = [responseObject valueForKey:@"data"];
        NSArray * cates = [THTieZiCateModel mj_objectArrayWithKeyValuesArray:stoneobs_net_array];
        if (handle) {
            handle(cates);
        }
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {

        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
        if (handle) {
            handle(@[]);
        }
    }];
}

//获取已购商品 和分类共用模型
+ (void)stoneobs_fun_get_did_buy_goos:(void(^)(NSArray * cates))handle{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/myGoods"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumGet
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSArray * stoneobs_net_array = [responseObject valueForKey:@"data"];
        NSArray * cates = [THTieZiCateModel mj_objectArrayWithKeyValuesArray:stoneobs_net_array];
        if (handle) {
            handle(cates);
        }
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        if (handle) {
            handle(@[]);
        }
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
//删除清单
+ (void)stoneobs_fun_send_delete_tiezi:(NSString*)t_id handle:(STTools_DataController_stoneobs_handle)handle{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    if (t_id.length) {
        [stoneobs_net_param_dic setObject:t_id forKey:@"id"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/del"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumDelete
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
        if (handle) {
            handle(nil,YES,stoneobs_net_model_dic);
        }
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
//添加评论
+ (void)addcommentFormPosts_id:(NSString*)posts_id content:(NSString*)content handle:(STTools_DataController_stoneobs_handle)handle{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
        
    }
    if (posts_id.length) {
        [stoneobs_net_param_dic setObject:posts_id forKey:@"posts_id"];
    }
    if (content.length) {
        [stoneobs_net_param_dic setObject:content forKey:@"content"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/comment"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumPost
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
        if (handle) {
            handle(nil,YES,stoneobs_net_model_dic);
        }
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
//点赞或者取消点赞
+ (void)addGoodOrCancleFormPosts_id:(NSString*)posts_id  handle:(STTools_DataController_stoneobs_handle)handle{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
        
    }
    if (posts_id.length) {
        [stoneobs_net_param_dic setObject:posts_id forKey:@"id"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/up"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumPost
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
        if (handle) {
            handle(nil,YES,stoneobs_net_model_dic);
        }
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
//收藏或者取消收藏
+ (void)addCollectionOrCancleFormPosts_id:(NSString*)posts_id  handle:(STTools_DataController_stoneobs_handle)handle{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
        
    }
    if (posts_id.length) {
        [stoneobs_net_param_dic setObject:posts_id forKey:@"id"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/collection"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumPost
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
        if (handle) {
            handle(nil,YES,stoneobs_net_model_dic);
        }
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
//关注或者取消关注
+ (void)addAttentionOrCancleFormUser_id:(NSString*)user_id  handle:(STTools_DataController_stoneobs_handle)handle{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
       NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
       NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
       if (stoneobs_net_user_id.length) {
           [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
       }
       if (stoneobs_net_user_token.length) {
           [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
           
       }
       if (user_id.length) {
           [stoneobs_net_param_dic setObject:user_id forKey:@"id"];
       }
       NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/follow"];
       DDLogInfo(@"url:%@",stoneobs_net_net_url);
       DDLogInfo(@"param:%@",stoneobs_net_param_dic);
       [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                    method:STHttpRequestType_stoneobs_enumPost
                                                                parameters:stoneobs_net_param_dic
                                                                   success:^(NSURLSessionDataTask *operation, id responseObject) {
           [SVProgressHUD dismiss];
           NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
           if (handle) {
               handle(nil,YES,stoneobs_net_model_dic);
           }
           // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
           DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
           
           
       } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
           [SVProgressHUD dismiss];
           [SVProgressHUD showErrorWithStatus:error.desc];
           DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                      stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
       }];
}
//帖子详情
+ (void)getTieZiDetailWithPosts_id:(NSString*)posts_id  handle:(void(^)(THTieZiModel*model))handle{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
       NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
       NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
       if (stoneobs_net_user_id.length) {
           [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
       }
       if (stoneobs_net_user_token.length) {
           [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
           
       }
       if (posts_id.length) {
           [stoneobs_net_param_dic setObject:posts_id forKey:@"id"];
       }
       NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/detail"];
       DDLogInfo(@"url:%@",stoneobs_net_net_url);
       DDLogInfo(@"param:%@",stoneobs_net_param_dic);
       [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                    method:STHttpRequestType_stoneobs_enumGet
                                                                parameters:stoneobs_net_param_dic
                                                                   success:^(NSURLSessionDataTask *operation, id responseObject) {
           [SVProgressHUD dismiss];
           NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
           THTieZiModel * model = [THTieZiModel mj_objectWithKeyValues:stoneobs_net_model_dic];
           if (handle) {
               handle(model);
           }
           // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
           DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
           
           
       } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
           [SVProgressHUD dismiss];
           [SVProgressHUD showErrorWithStatus:error.desc];
           DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                      stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
       }];
}
@end
